package com.warrantyhotel.android.adapter;

import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.TextView;

import com.warrantyhotel.android.R;
import com.warrantyhotel.android.db.WarrantyHotelDBSchema.StateTable;

public class StatesAdapter extends CursorAdapter
{

	private LayoutInflater mInflater;

	public StatesAdapter(Context context, Cursor c)
	{
		super(context, c, false);
		mInflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public void bindView(View view, Context context, Cursor cursor)
	{
		final CountryItem item = (CountryItem) view.getTag();
		item.stateName.setText(cursor.getString(cursor
				.getColumnIndex(StateTable.STATE_NAME)));
	}

	@Override
	public View newView(Context context, Cursor cursor, ViewGroup parent)
	{
		CountryItem item = new CountryItem();
		View view = mInflater.inflate(R.layout.spinner_state_item, null);
		item.stateName = (TextView) view.findViewById(R.id.state_name);
		view.setTag(item);
		return view;
	}

	public static class CountryItem
	{
		public TextView stateName;
	}

}
